﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ChequeManagement.BLL
{
    /// <summary>
    ///This Class contains number of Field,properties,method and this class inheritance of BaseObject class
    /// </summary>
    /// <field> this field use in IsValid method for set parameter ApplicationInfo class and properties and constructor  </field>
    /// <properties>this properties contain set for receive value and contain get for return value</properties>
    /// <method>this class contain IsValid method for Validation all properties</method>
    /// <constructor>this class include two constructor that one not have overload and other have overload</constructor>
    public class BLLChequeCategory : BaseObject
    {



        #region Fields
        /// <summary>
        /// This data member name is "accountNo" and type is long?
        /// </summary>
        private long? accountNo;
        /// <summary>
        /// This data member name is "branchName" and type is string
        /// </summary>
        private string branchName;
        /// <summary>
        /// This data member name is "chequeCategoryID" and type is long?
        /// </summary>
        private long? chequeCategoryID;
        /// <summary>
        /// This data member name is "chequeCategoryName" and type is string
        /// </summary>
        private string chequeCategoryName;
        /// <summary>
        /// This data member name is "firstPageNo" and type is long
        /// </summary>
        private long firstPageNo;
        /// <summary>
        /// This data member name is "pageCount" and type is int
        /// </summary>
        private int pageCount;
        /// <summary>
        /// This data member name is "bankObject" and type is BLL.BLLBank
        /// </summary>
        private BLL.BLLBank bankObject;
        /// <summary>
        /// This data member name is "bankID" and type is int
        /// </summary>

        private int bankID;


        #endregion

        #region Properties

        /// <summary>
        ///  This property contain set for receive value and contain get for return value
        /// </summary>
        public long AccountNo
        {
            set
            {
                accountNo = value;
            }

            get
            {
                return accountNo.Value;
            }

        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public string BranchName
        {
            set
            {
                branchName = value;
            }
            get
            {
                return branchName;
            }
        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public long ChequeCategoryID
        {
            set
            {
                chequeCategoryID = value;
            }
            get
            {
                return chequeCategoryID.Value;
            }
        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public string ChequeCategoryName
        {
            set
            {
                chequeCategoryName = value;
            }
            get
            {
                return chequeCategoryName;
            }

        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public long FirstPageNo
        {

            set
            {
                firstPageNo = value;
            }
            get
            {
                return firstPageNo;
            }
        }

        /// <summary>
        ///This property contain set for receive value and contain get for return value
        /// </summary>
        public int PageCount
        {
            set
            {
                pageCount = value;
            }
            get
            {
                return pageCount;
            }
        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public BLL.BLLBank BankObject
        {
            get
            {
                return bankObject;
            }
            set
            {
                bankObject = value;
            }
        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public int BankID
        {
            get
            {
                return bankID;
            }
            set
            {
                bankID = value;
            }
        }

        /// <summary>
        /// This enum include some member
        /// </summary>
        public enum ChequeCategoryField
        {
            ChequeCategoryID,
            BankID,
            ChequeCategoryName,
            BranchName,
            AccountNo,
            FirstPageNo,
            PageCount
        }

        #endregion

        #region Methods
        /// <summary>
        /// This constructor include some parameter that get parameter and set they value with field member value
        /// and use on create instance of class
        /// </summary>
        /// <param name="accountNo" Type="long"></param>
        /// <param name="branchName" Type="string"></param>
        /// <param name="chequeCategoryID" Type="long"></param>
        /// <param name="chequeCategoryName" Type="string"></param>
        /// <param name="firstPageNo" Type="long"></param>
        /// <param name="pageCount" Type="int"></param>
        public BLLChequeCategory(long accountNo, string branchName, long chequeCategoryID, string chequeCategoryName, long firstPageNo, int pageCount)
        {
            this.accountNo = accountNo;
            this.branchName = branchName;
            this.chequeCategoryID = chequeCategoryID;
            this.chequeCategoryName = chequeCategoryName;
            this.firstPageNo = firstPageNo;
            this.pageCount = pageCount;
        }
        /// <summary>
        /// This constructor not have parameter and use on create instance of class
        /// </summary>
        public BLLChequeCategory()
        {
        }

        /// <summary>
        /// This method check fields value
        /// </summary>
        /// <param name="excepts" Type="string[]"></param>
        /// <accountNo>if accountNo not has value this method add error</accountNo>
        /// <branchName>if branchName value is empty this method add error</branchName>
        /// <chequeCategoryName>if chequeCategoryName value is empty this method add error </chequeCategoryName>
        /// <firstPageNo>if firstPageNo length less or equal of zero this method add error</firstPageNo>
        /// <pageCount>if pageCount value less of 25,this method add error</pageCount>
        /// <ErrorsCount>ErrorsCount is a  property and defined on BaseObject class and this property return a number that this number show count error</ErrorsCount>
        /// <returns>if all field is Valid,ErrorsCount value is zero and return true else ErrorsCount value Larger of zero return false</returns>
        public bool IsValid(params string[] excepts)
        {
            Validation.ValidationRule vrObj = new Validation.ValidationRule();
            if (!accountNo.HasValue)
            {
                AddError("شماره حساب وارد نشده است", null);
            }
            else
            {

            }

            string branch;
            vrObj.DefaultMessageForNameIsValid = Validation.ValidationRule.DefaultForNameIsValid.Branch;
            if (!vrObj.NameIsValid(branchName, 3, 15, out branch))
                {
                    AddError(branch, null );
                }

            string name;
            vrObj.DefaultMessageForNameIsValid = Validation.ValidationRule.DefaultForNameIsValid.Name;
            if(!vrObj.NameIsValid(chequeCategoryName, 2, 30, out name))
            {
                AddError(name, null);
            }


            //if (chequeCategoryName == string.Empty)
            //{
            //    AddError("نام صادر کننده چک وارد نشده است", null);
            //}
            //else
            //{

            //}

            if (firstPageNo <= 0)
            {
                AddError("شماره صفحه اول دسته چک درست نشده است", null);
            }
            else
            {

            }

            if (pageCount < 25)
            {
                AddError("تعداد برگهای دسته چک درست وارد نشده است", null);
            }
            else
            {

            }
            if (ErrorsCount > 0)
                return false;
            else
                return true;
        #endregion
        }
    }
}
